﻿


function grid_processDef_add() {
    //location.href =decodeURIComponent("/User/UserAdd") ;
    grid_processDef_show();
}

function save_ProcessDef() {
    //addDialog.frame.save();
    var form = $('#frmProcessDef');
    form.submit();
}

function grid_processDef_edit() {
    if (processdefgrid.getSelecteds().length == 0) {
        $.ligerDialog.warn('至少选择一个流程进行修改！', '温馨提示');
        return;
    }
    var processdef = processdefgrid.getSelected();
    grid_processDef_show(processdef.ID, processdef.ProcessDefName, processdef.ProcessType);
}

function grid_processDef_show(ID, ProcessDefName, ProcessType) {
    var title = "添加流程";
    
    if (ProcessDefName != null) {
        title = "修改流程【 " + ProcessDefName + " 】"
        processDef_set(ProcessDefName, ID, ProcessType);
    } else {
        processDef_reset();
    }
    saveDialog = $.ligerDialog.open({
        title: title,
        id: 'processDefDialog',
        name: 'processDefDialog',
        slide: false,
        isHidden: false,
        modal: true,
        target: $("#frmProcessDef"),
        //        url: "/process/UserAdd",
        width: 400, isResize: true, allowClose: false,
        buttons: [
                    { text: '保存', onclick: save_ProcessDef },
                    {
                        text: '取消', onclick: function (item, dialog) {
                            dialog.hide();
                            processDef_reset();
                        }
                    }
                ]
    });
}
function processDef_set(processdefname,defid,type) {
    //$("#txtUserName").ligerTextBox('option', 'disabled', false);
    selType.setValue(type);
    $("#txtProcessDefName").val(processdefname);
    $("#processdefID").val(defid);
    $("#lblmsg").html("");
}


function processDef_reset() {
    $(".l-text-field").ligerHideTip();
    selType.selectIndex(0);
    $("#txtProcessDefName").val("");
    $("#processdefID").val("0");
    $("#lblmsg").html("");
}

function grid_processDef_delete() {
    var processIDs = "";
    var names = "";

    if (processdefgrid.getSelecteds().length == 0) {
        $.ligerDialog.warn('至少选择一个流程进行删除！', '温馨提示');
        return;
    }
    var selected = processdefgrid.getSelecteds();
    if (selected.length == 0) {
        $.ligerDialog.warn('请选择要删除的数据！', '温馨提示');
        return;
    }

    for (var i = 0; i < selected.length; i++) {
        processIDs += selected[i].ID + ",";
        names += selected[i].ProcessDefName + ",";
    }
    names = names.substring(0, names.length - 1);
    processIDs = processIDs.substring(0, processIDs.length - 1);
    processDef_delete(processIDs, names);

}

function processDef_delete(processIDs, realName) {
    $.ligerDialog.confirm('确定删除流程[' + realName + ']吗？', '温馨提示', function (result) {
        if (result) {
            $.ajax({
                url: '/process/ProcessDefDelete',
                data: "processDefIDs=" + processIDs,
                type: "post",
                success: function (result) {
                    if (result == "1") {
                        //employee.deleteSelectedRow();
                        $.ligerDialog.success("成功删除流程[" + realName + "]。");
                        grid_processDef_refresh();
                    } else {
                        $.ligerDialog.error('删除失败！', '温馨提示');
                    }
                }
            });
        }
    });
}
function changestate(id, state, realName) {
    var statestr = "禁用";
    if (state == 1) {
        statestr = "启用";
    }
    $.ligerDialog.confirm('确定【' + statestr + '】流程[' + realName + ']吗？', '温馨提示', function (result) {
        if (result) {
            $.ajax({
                url: '/process/ProcessDefChangeStatus',
                data: "processDefID=" + id + "&status=" + state,
                type: "post",
                success: function (result) {
                    if (result == "1") {
                        //employee.deleteSelectedRow();
                        $.ligerDialog.success(statestr + "流程成功");
                        grid_process_refresh();
                    } else {
                        $.ligerDialog.error(statestr + "流程失败！", '温馨提示');
                    }
                }
            });
        }
    });
}
function grid_processDef_refresh() {
    processdefgrid.setOptions(
             {
                 parms:
                [
                    { name: "page", value: 1 }
                ]
             });
    processdefgrid.loadData();
}
 